<?php
abstract class Component_Abstract {
	
	private $_config;
        private $_tableName;
        private $_componentsPath;
        private $_componentDir;
        private $_options;
        private $_jqGridTheme;
        private $_imagesUri;
        private $_params;
        private $_label;

        public function setLabel($label) {
            $this->_label=$label;
            return $this;
        }

        public function getLabel() {
            return $this->_label;
        }

        public function setImagesUri($data) {
            $this->_imagesUri=$data;
            return $this;
        }
        
        public function getImagesUri() {
            return $this->_imagesUri;
        }

        public function setJqGridTheme($theme) {
            $this->_jqGridTheme=$theme;
            return $this;
        }

        public function getJqGridTheme() {
            return $this->_jqGridTheme;
        }

        public function setOptions($options) {
            $this->_options=$options;
        }
        
        public function getOptions() {
            return $this->_options;
            return $this;
        }

        public function setComponentsPath($path) {
            $this->_componentsPath=$path;
            return $this;
        }

        public function getComponentsPath() {
            return $this->_componentsPath;
        }

        public function setComponentDir($dir) {
            $this->_componentDir=$dir;
            return $this;
        }

        public function getComponentDir() {
            return $this->_componentDir;
        }

	public function setConfig($config) {
		$this->_config=$config;
            return $this;
	}

        public function getConfig() {
		return $this->_config;
	}

        public function setTableName($tableName) {
            $this->_tableName=$tableName;
            return $this;
        }

        public function getTableName($tableName) {
            return $this->_tableName;
        }

        public function setParams($data) {
            $this->_params=$data;
            return $this;
        }

        public function getParams() {
            return $this->_params;
        }

        public function getParameter($parameter) {
            return isset($this->_params[$parameter]) ? $this->_params[$parameter] : null;
        }

        public function  __construct($jqGridTheme,$componentsPath,$componentDir,$imagesUri,$params=array(),$label='label') {
                $iniFile=$componentsPath.DIRECTORY_SEPARATOR.$componentDir.DIRECTORY_SEPARATOR.'ini'.DIRECTORY_SEPARATOR.$componentDir.'.ini';
		$config = new Zend_Config_Ini($iniFile,'default');

                $this->setConfig($config)
                     ->setComponentsPath($componentsPath)
                     ->setComponentDir($componentDir)
                     ->setJqGridTheme($jqGridTheme)
                     ->setParams($params)
                     ->setImagesUri($imagesUri)
                     ->setTableName(isset($this->_config->db->table) ? $this->_config->db->table : '')
                     ->setLabel($label);

                $this->initComponent();
            
        }

        public function getTmplContent($tpl) {
            if (!$tpl)
                    throw new Exception("please select a template");
            
            $includeFile=$this->getComponentsPath().DIRECTORY_SEPARATOR.
                      $this->getComponentDir().DIRECTORY_SEPARATOR.
                        'php'.DIRECTORY_SEPARATOR.
                            'phtml'.DIRECTORY_SEPARATOR.$tpl.'.phtml';
            ob_start();
            require($includeFile);
            $ret = ob_get_clean();

            return $ret;

        }

        abstract public function initComponent();
	abstract public function show();
	abstract public function demo();
        abstract public function getConfigPage();
        abstract public function getOptionsDiv();

	
}